﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace monitor_server_2_WPF
{
    /// <summary>
    /// Dockpanel with image and textblock.
    /// </summary>
    class MyDockPanel : DockPanel, IComparable
    {
        readonly Image _image = new Image { Stretch = Stretch.None, Margin = new Thickness(0, 3, 0, 3) };
        private readonly TextBlock _tb;
        //static RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality);

        public enum DeviceTreeNodeHeaderImage
        {
            Region,
            Station,
            ActiveDevice,
            InactiveDevice
        }

        public MyDockPanel(DeviceTreeNodeHeaderImage imageType, string header)
        {
            RenderOptions.SetBitmapScalingMode(_image, BitmapScalingMode.HighQuality);
            //RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.NearestNeighbor);
            //RenderOptions.SetEdgeMode(image,EdgeMode.Aliased);
            switch (imageType)
            {
                case DeviceTreeNodeHeaderImage.Region:
                    _image.Source = Res.GetBitMapFromPng("direction_16");
                    break;
                case DeviceTreeNodeHeaderImage.Station:
                    _image.Source = Res.GetBitMapFromPng("antenna_16");
                    break;
                case DeviceTreeNodeHeaderImage.ActiveDevice:
                    _image.Source = Res.GetBitMapFromPng("Circle_Blue_16");
                    break;
                case DeviceTreeNodeHeaderImage.InactiveDevice:
                    _image.Source = Res.GetBitMapFromPng("Circle_Grey_16");
                    break;
            }

            _tb = new TextBlock
            {
                Margin = new Thickness(5, 0, 0, 0),
                Text = header,
                VerticalAlignment = VerticalAlignment.Center,
                Foreground = new SolidColorBrush(Colors.White)
            };
            Children.Add(_image);
            Children.Add(_tb);
            Margin = new Thickness(5, 0, 5, 0);
        }

        public MyDockPanel(BitmapImage image, string header)
        {
            RenderOptions.SetBitmapScalingMode(_image, BitmapScalingMode.HighQuality);

            _image.Source = image;

            _tb = new TextBlock
            {
                Margin = new Thickness(5, 0, 0, 0),
                Text = header,
                VerticalAlignment = VerticalAlignment.Center,
                Foreground = new SolidColorBrush(Colors.White)
            };
            Children.Add(_image);
            Children.Add(_tb);
            Margin = new Thickness(5, 0, 5, 0);
        }

        public override string ToString()
        {
            return _tb.Text;
        }

        public int CompareTo(object obj)
        {
            return String.Compare(ToString(), obj.ToString(), StringComparison.Ordinal);
        }
    }
}
